package cn.zn.controller.system;

import cn.zn.base.bean.dto.ResultData;
import cn.zn.base.common.utils.ResultUtil;
import cn.zn.dept.entity.SysDept;
import cn.zn.dept.service.SysDeptService;
import cn.zn.dept.vo.SysDeptPageVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * 部门信息
 *
 * @author zn-admin
 */
@RestController
@RequestMapping("/system/dept")
public class SysDeptController {

    @Autowired
    private SysDeptService deptService;

    /**
     * 获取部门列表
     */
    @PreAuthorize("@ss.hasPermi('system:dept:list')")
    @GetMapping("/list")
    public ResultData list(SysDeptPageVo vo) {
        List<SysDept> depts = deptService.selectDeptList(vo);
        return ResultUtil.success(depts);
    }

    /**
     * 根据部门编号获取详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:dept:info')")
    @GetMapping(value = "/{deptId}")
    public ResultData getInfo(@PathVariable String deptId) {
        return ResultUtil.success(deptService.getById(deptId));
    }

    /**
     * 获取部门列表
     */
    @GetMapping("/tree")
    public ResultData tree() {
        List<SysDept> deptTree = deptService.selectDeptTree();
        return ResultUtil.success(deptTree);
    }

}
